<?php

class LawyerSeeder extends Seeder {

    /**
     * 把律师接单数移植到一个字段，这样我们就可以根据这个字段来排序了。
     */
    public function run() 
    {
		try {
            $lawyers = Lawyer::all();
            
            // // 找出不带article_info的articles，然后添加空白的article_info
            foreach($lawyers as $lawyer) {
                $case_count = Post
                    ::leftJoin('post_thread', 'posts.id', '=', 'post_thread.post_id') 
                    ->where('post_thread.user_id', '=', $lawyer->user_id)
                    ->count();
                $lawyer->case_count = (int)$case_count;
                $lawyer->save();
            }
		} catch(Exception $ex){
			Log::error($ex);
		}
    }
}